package util.apps;
import java.io.*;
import util.gen.*;

public class MergeColumns {

	
	/**
	 * Merges the columns of two files using a tab, assumes the same length!
	 */
	public static void main(String[] args) {
		if (args.length !=2) Misc.printExit("\nEnter two files of equal length to merge with a tab.\n");
		try{
			File file1 = new File (args[0]);
			File file2 = new File (args[1]);
			BufferedReader in1 = new BufferedReader(new FileReader(file1));
			BufferedReader in2 = new BufferedReader(new FileReader(file2));
			PrintWriter out = new PrintWriter(new FileWriter(new File(file1.getParent(), file1.getName()+"_"+file2.getName()+".merged")));
			String line1;
			String line2;

			while ((line1 = in1.readLine()) !=null  && (line2 = in2.readLine()) !=null){
					out.println(line1+"\t" +line2);
			}
			if (in1.readLine() != null || in2.readLine() !=null) System.out.println("\nWARNING: Files are of unequal length! Trunkated merged file.\n");
			in1.close();
			in2.close();
			out.close();
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
